﻿using UnityEngine;
using System.Collections;

public class BossBattleResultPopup : MonoBehaviour {
	public UILabel legionExp;
	public GameObject[] rewardOnObject;
	public GameObject[] rewardOffObject;
	public GameObject addFriendObject;
	public UILabel addFriendLabel;
	public GameObject friendRewardObject;
	public UILabel friendRewardLabel;
	public GameObject addFriendButtonObject;

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}

	public void OnClickedAddFriendButton()
	{
		NetworkManager.Instance.C2S_FRIEND_SEND_REQ(UserData.Instance.battleFriendId, (responseData) => {
			if (responseData.ecode != 0)
			{
				// TODO: 친구 추가 후 에러 발생시 처리
				if( responseData.ecode != 0 )
				{
					Popup_OneButton po = PopupManager.PushPopup(PopupKind.OneButton) as Popup_OneButton;
					po.SetPopupWithTitleAndBody(TextController.GetStringWithId("uiCommonTextwarning"), TextController.GetStringWithId(string.Format("systemErrorText{0}", Mathf.Abs(responseData.ecode))));
					return;
				}
			}
			else
			{
				// TODO: 친구 추가 이후 결과 처리
				addFriendButtonObject.SetActive(false);
				addFriendLabel.text = TextController.GetStringWithId("uiFriendBattleSend").Replace("{0}", string.Format("Lv {0}", UserData.Instance.battleFriend.lv.ToString())).Replace("{1}", UserData.Instance.battleFriend.name);
			}
		});
	}

	public void OnClickedOkButton()
	{
		UserData.Instance.raidBossId = 0;
		UserData.Instance.raidBossStartData = null;
		UserData.Instance.raidBossResultData = null;

        //if( WorldSceneManager.isSentSearch )
        //{
        //    SceneController.LoadLevel("World");
        //}
        //else
        //{
        //    SoundController.PlayBGM("BGM_Main");
        //    SceneController.LoadLevel("BossList");
        //}

        //(지스타 임시)
        SceneController.LoadLevel("Main");
	}
}
